<?php

namespace App\Http\Controllers;

use App\Models\Report;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;

class ReportsController extends Controller
{
    public function index(Request $request)
    {
        $data = Report::requestCriteria($request)->paginate($request->query('limit'));
        return $this->respondSuccess($data);
    }
    public function show(Report $report)
    {
        $report->load(['ESCluster']);

        $info = [
            ['type' => '安全性', 'score' => rand(93, 96) / 100, 'level' => '正常', 'advice' => '' ],
            ['type' => '经济性', 'score' => rand(80, 96) / 100, 'level' => '正常', 'advice' => '' ],
            ['type' => '可靠性', 'score' => rand(90, 96) / 100, 'level' => '正常', 'advice' => '' ],
        ];
        $analysis = [
            ['内阻' => 4, '特征向量' => rand(3, 4), '极化参数' => rand(3, 4), '时间差值' => rand(3, 4), '离散度' => rand(3, 4), ],
            ['内阻' => 4, '特征向量' => rand(3, 4), '极化参数' => rand(4, 5), '时间差值' => rand(3, 4), '离散度' => rand(3, 4),],

        ];
        $report['hash_code'] = Hash::make('Hallo hash code');
        $report['diagnosis_nums'] = count($report['result']);
        $report['diagnosis_info'] = $info;
        $report['analysis_info'] = $analysis;
        return $this->respondSuccess($report);
    }
}
